package com.mysafe.provision.view.login;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;

import com.mysafe.provision.model.account.Account;
import com.mysafe.provision.service.account.IAccountService;

@Named
@ConversationScoped
public class LoginScreen implements Serializable {

	private static final long serialVersionUID = 3559479570474610379L;

	@Inject private Conversation conversation;
	@Inject private Account account;

	private IAccountService accountService;
	
	public LoginScreen() {
	}
	
	@Inject
	public LoginScreen(IAccountService accountService) {
		this.accountService = accountService;
	}
	
	@PostConstruct
	public void init() {
		conversation.begin();
	}
	
	public String verifyAccess() {
		Boolean verified = Boolean.valueOf(accountService.verifyAccess(account));
		if (verified) {
			account.setLogged(true);
		}
		return verified.toString();
	}
	
	public void finalize() {
		conversation.end();
	}
	
	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

}
